/*
 * @Author: wangke
 * @Date: 2025-03-13 22:44:17
 * @LastEditors: wangke
 * @LastEditTime: 2025-03-14 00:15:05
 * 
 */
#ifndef BSPOID_H
#define BSPOID_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "App_Common.h"
// #include "snc_drv_gpio.h"
#include "stdint.h"
/* Exported defines ----------------------------------------------------------*/
    
#define BSP_OID_USE_NRST 0 /**< Define use reset pin for oid or not; 0 unused; 1 use */
    
#if BSP_OID_USE_NRST
#define BSP_OID_NRSTIO ( GPIO_PORT_0_P10 ) /**< Define reset gpio for oid */
#endif
#define BSP_OID_SCKIO ( GPIO_PORT_0_P08 ) /**< Define sck gpio for oid */
#define BSP_OID_SDIOIO ( GPIO_PORT_0_P09 ) /**< Define sdio gpio for oid */

/* Exported types ------------------------------------------------------------*/
    
typedef enum
{
    BSP_OID_OLD64BIT = 0,       /**< Oid old 64bit format */
    BSP_OID_OLD96BIT,           /**< Oid old 96bit format */
} BSP_OID_FORMAT_E;

typedef enum
{
    BSP_OID_VER_UNKNOW = 0,     /**< Unknow version */
    BSP_OID_VER_ROM003,         /**< Rom 003 version */
    BSP_OID_VER_ROM005,         /**< Rom 005 version */
    BSP_OID_VER_ROM006,         /**< Rom 006 version */
    BSP_OID_VER_ROM008,         /**< Rom 008 version */
    BSP_OID_VER_ROM009,         /**< Rom 009 version */
    BSP_OID_VER_ROM011,         /**< Rom 011 version */
} BSP_OID_VER_E;

typedef enum
{
    BSP_OID_TYPE_UNKNOW = 0,    /**< Unkonw data type */
    BSP_OID_TYPE_DECFAIL,       /**< Invalid as decode fail */
    BSP_OID_TYPE_LESSDOT,       /**< Invalid as less dot */
    BSP_OID_TYPE_ANGLEONLY,     /**< Invalid as only angle */
    BSP_OID_TYPE_CHKSUMERR,     /**< Checksum error */
    BSP_OID_TYPE_2GEN,          /**< Oid2 general */
    BSP_OID_TYPE_3GEN,          /**< Oid3 general */
    BSP_OID_TYPE_3SGEN,         /**< Oid3S general */
    BSP_OID_TYPE_3P5GEN,        /**< Oid3.5 general */
    BSP_OID_TYPE_4GEN,          /**< Oid4 general */
    BSP_OID_TYPE_OLDGEN,        /**< Oid general for old format */
    BSP_OID_TYPE_3POS,          /**< Oid3 position */
    BSP_OID_TYPE_3SPOS,         /**< Oid3s position */
    BSP_OID_TYPE_4POS,          /**< Oid4 position */
    BSP_OID_TYPE_4C,            /**< Oid4c position */
    BSP_OID_TYPE_OLDPOS,        /**< Oid position for old format */
    BSP_OID_TYPE_CMD,           /**< Cmd ack type */
} BSP_OID_TYPE_E;

typedef struct
{
    BSP_OID_TYPE_E eType;       /**< Parsed data type */
    uint32_t       ulData1;     /**< Data1 for oid general low 32bits or x position * 128 */
    uint32_t       ulData2;     /**< Data1 for oid general high 32bits or y position * 128 */
    uint32_t       ulAngle;     /**< Angle data */
} Bsp_Oid_Data_t;

/* Exported functions prototypes ---------------------------------------------*/

void Bsp_Oid_Init( void );
#if BSP_OID_USE_NRST
void Bsp_Oid_EnterReset( void );
void Bsp_Oid_LeaveReset( void );
#endif
int32_t Bsp_Oid_StartUp( BSP_OID_FORMAT_E eStartUpFmt );
bool Bsp_Oid_CheckRx( void );
int32_t Bsp_Oid_GetData( Bsp_Oid_Data_t* ptOidData );
int32_t Bsp_Oid_SendCmd( uint8_t ucCmd );
int32_t Bsp_Oid_ReadReg( uint16_t usAddr , uint16_t* pusData );
int32_t Bsp_Oid_WriteReg( uint16_t usAddr , uint16_t usData );
int32_t Bsp_Oid_EnterSleep( void );
int32_t Bsp_Oid_LeaveSleep( void );
int32_t Bsp_Oid_GetRomVer( BSP_OID_VER_E* peRomVer );

#ifdef __cplusplus
}
#endif


#endif